<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\Admin\DeptService;
use App\Http\Requests\Admin\DeptRequest;
use App\Models\Dept;

class DeptController extends Controller
{

    public function options()
    {

        $data = DeptService::options();

        return $this->success(data: $data);
    }


    /**
     * 显示资源列表。
     */
    public function index(Request $request)
    {

        $params = $request->only('keywords', 'status');

        $data = DeptService::index($params);

        return $this->success(data: $data);
    }

    /**
     * 将新创建的资源存储到数据库。
     */
    public function store(DeptRequest $request)
    {

        $validated = $request->validated();

        $data = DeptService::store($validated);

        return $this->success(data: $data);
    }

    /**
     * 显示指定资源的详细信息。
     */
    public function show(string $id)
    {

        $data = DeptService::show($id);

        return $this->success(data: $data);
    }

    /**
     * 更新指定资源。
     */
    public function update(DeptRequest $request, string $id)
    {
        $validated = $request->validated();

        $data = DeptService::update($validated, $id);

        return $this->success(data: $data);
    }

    /**
     * 删除指定资源。
     */
    public function destroy(string $id)
    {
        $data = DeptService::destroy($id);

        return $this->success(data: $data);
    }
}
